<%@ page contentType="text/html; charset=UTF-8"%>
<%@ page import="com.dd.*,com.javapig.util.*,java.util.*"%>
<%@ page import="com.dd.XiaLaLiebiaoInfos" %>
<%@ page import="com.dd.XiangMu,com.dd.exception.*" %>
<%@ page import="com.javapig.util.*,com.dd.*,com.dd.exception.*"%>
<%@ page import="com.jspsmart.upload.SmartUpload" %>

<%@ include file="global.jsp" %>
<%	



	ArrayList allShiYebus = XiangMuShiYeBuManager.GetAllXiangMuShiYeBuInfos();
	int nShiYeBuCount = allShiYebus.size();
	
	String strErrorInfo = "";
	int addTest = ParamUtils.getIntParameter(request,
			"add", -1);
	
	boolean addXiangFailed = false;
	if (addTest == 1) {
		
		//名称
		String mingCheng = ParamUtils.getParameter(request, "mingCheng");
		System.out.println(mingCheng);
		//项目简称
		String jianCheng = ParamUtils.getParameter(request, "jianCheng");
		System.out.println(jianCheng);
		//String picPath = ParamUtils.getParameter(request, "picPath");
		
		//所属项目事业部
		int xiangMuShiYeBuID = ParamUtils.getIntParameter(request,"ddxiangMuShiYebu",-1);
		System.out.println(xiangMuShiYeBuID);
		
		//后台我已经加了过滤器强制用UTF-8，所以编写页面也都要用UTF-8编码，两者一致就不会出现乱码
		//取URL上的参数用ParamUtils类，已经做好基本操作的封装
		String sContent = ParamUtils.getParameter(request, "content");
		System.out.println(sContent);
		//缩略图地址
		String picPath = ParamUtils.getParameter(request,"picPath");
		System.out.println(picPath);
		//String sContent = new String(request.getParameter("content")
		//.getBytes("iso-8859-1"));//new String(request.getParameter("content1").getBytes("UTF-8"));
		if (sContent != null) {
			System.out.print("取得的html标记:" + "\n" + sContent);
		}
		boolean berror = false;
		if(mingCheng == null ||jianCheng == null || sContent == null ||
			mingCheng.length() <=0 || jianCheng.length() <= 0 || sContent.length() <=0	)
		{
			strErrorInfo = strErrorInfo + "信息没有填写完整:";
			berror = true;
		}
		if(picPath == null || picPath.length() <=0)
		{
			strErrorInfo = strErrorInfo + "项目的缩略图为空";
			berror = true;
		}
		if(xiangMuShiYeBuID == -1)
		{
			strErrorInfo = strErrorInfo + "项目事业部为空:";
			berror = true;
		}
		
		if(berror == false)
		{
			XiangMu newXiangmu = new XiangMu();
			if(newXiangmu != null)
			{
				try
				{
					newXiangmu.InsertXiangMu(mingCheng,xiangMuShiYeBuID,jianCheng,sContent,picPath);
				}
				catch(Exception ue)
				{
					berror = true;
					strErrorInfo = strErrorInfo + "数据库操作失败";
				}
				
			}
		}
		
		if(berror == false)
		{
			response.sendRedirect("prjView.jsp");
			return;
		}
		else
		{
			addXiangFailed = true;
		}
		
	}
%>
<%@ include file="header.jsp" %>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<p>

<%
    String title = "创建项目";
    String[][] breadcrumbs = {
        {"主页面", "main.jsp"},
        {title, "createUser.jsp"}
    };
    StringBuffer pageGuide = new StringBuffer();
    for (int i=0; i<breadcrumbs.length; i++){
      for(int j=0; j<breadcrumbs[i].length; j++){
          pageGuide.append(breadcrumbs[i][j]+"@");
      }
    }

%>

<jsp:include page="title.jsp" flush="true">
   <jsp:param name="title" value="<%=title%>" />
   <jsp:param name="pageGuide" value="<%=pageGuide%>" />
</jsp:include>

<font size="-1">
	<%
		if(addXiangFailed)
		{
	%>
		<span id="errorInfo" style="color:Red;">创建项目时发生错误!!(<%=strErrorInfo %>)</span>	
	
	<% } %>
</font>
<FORM method="POST"  name="myform" action="createPrj.jsp?add=1">
<TABLE border="0" cellpadding="2" cellspacing="1" bgcolor="<%= tblBorderColor %>">

	<TR>
		<TD bgcolor="#FFFFFF">项目部详细名称</TD>
		<TD bgcolor="#FFFFFF"><label> <input type="text" name="mingCheng"
			id="mingCheng" size="30"> </label></TD>
	</TR>
	<TR>
		<TD width="112" bgcolor="#FFFFFF">项目部缩写</TD>
		<TD width="502" bgcolor="#FFFFFF"><label> <input name="jianCheng"
			type="text" id="jianCheng" size="30"> </label></TD>
	</TR>
		<TR>
		<TD width="112" bgcolor="#FFFFFF">项目所属事业部</TD>
		<TD width="502" bgcolor="#FFFFFF">
			  <font color="#FFFFFF">
                <select name="ddxiangMuShiYebu" id="ddxiangMuShiYebu" style="width:158px;">
                   <%
                    		if(nShiYeBuCount > 0)
                    		{
                    	 				Iterator it = allShiYebus.iterator();
                    	 				while(it.hasNext())
                    	 				{
                    	 					XiangMuShiYeBu mx = (XiangMuShiYeBu)it.next();
                    	 					if(mx != null)
                    	 					{
                    	 	
                 	 %>   
                   		 <option value="<%=mx.getXiangMuShiYeId()%>"><%=mx.getShiYeBuMingCheng()%></option>   
      
                   <%
                    	 					}
                    	 				}
                    			}
                    		else
                    		{
                  	 %> 
                  	  <option value="-1">请先创建事业部</option>  
                  	 <%} %>                                                      
               </select>
            </font>
		</TD>
	</TR>
	<TR>
		<TD width="112" bgcolor="#FFFFFF">项目部缩略图</TD>
		<TD width="502" bgcolor="#FFFFFF"><label>
		<input name="picPath" type="hidden" id="picPath" size="40" maxlength="100"><iframe class="TBGen" style="top:2px" ID="UploadFiles" src="upload/upload.jsp" frameborder=0 scrolling=no width="400" height="24"> </iframe> </label></TD>
	</TR>
	<TR>
		<TD bgcolor="#FFFFFF">项目部描述：</TD>
		<TD bgcolor="#FFFFFF"><INPUT type="hidden" name="content" value="  "><IFRAME
			ID="eWebEditor1" src="eWebEditor.jsp?id=content&style=CoolBlue"
			frameborder="0" scrolling="no" width="500" height="250"></IFRAME></TD>

	</TR>
	<TR>
		<TD width="112" bgcolor="#FFFFFF">&nbsp;</TD>
		<TD width="502" bgcolor="#FFFFFF"><label> <input type="submit"
			name="Submit" value="提交"> </label></TD>
	</TR>
</TABLE>

</FORM>

</BODY>
</HTML>
